/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package enteties.article;

import java.util.ArrayList;
import java.util.Collection;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import util.article.SizeDetails;

/**
 *
 * @author Joris
 */
@Stateless
public class Size1Facade extends AbstractFacade<Size1> implements Size1FacadeLocal {
    @PersistenceContext(unitName = "Liebaut-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public Size1Facade() {
        super(Size1.class);
    }
    
    @Override
    public Integer createSize(String name) {
        Size1 size = new Size1();
        size.setName(name);
        create(size);
        return size.getId();
    }
    
    @Override
    public void editSize(Integer id, String name){
        Size1 size = find(id);
        size.setName(name);
        edit(size);
    }
    
    @Override
    public void removeSize(Integer id){
        Size1 size = find(id);
        remove(size);
    }
    
    @Override
    public SizeDetails getSize(Integer id){
        return convert(find(id));
    }
    
    @Override
    public Size1 createSize(SizeDetails sd, Article a){
        Size1 size = new Size1();
        size.setName(sd.getName());
        size.setArticleid(a);
        create(size);
        return size;
    }
    
    @Override
    public SizeDetails convert(Size1 size){
        if(size == null)
            return null;
        return new SizeDetails(size.getId(), size.getName());
    }
    
    @Override
    public Collection<SizeDetails> convert (Collection<Size1> sizes){
        Collection<SizeDetails> details = new ArrayList<SizeDetails>();
        for(Size1 size : sizes){
            details.add(convert(size));
        }
        return details;
    }
    
}
